package DAO;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * Trida pouzita pro pripojeni k MySQL databazi
 * @author vojta
 */
public class MySQLConnector {

    private static Connection connection = null;

    /**
     * Ziskani pripojeni
     * @return Connection - pripojeni k DB
     * @throws Exception 
     */
    public static Connection getConnection() throws Exception {
        if (connection == null) {
            connect();
        }
        return connection;

    }

    /**
     * Pripojeni k DB
     */
    private static void connect() {        
        try {
            // Natazeni driveru pro MySQL
            Class.forName("com.mysql.jdbc.Driver");
            // Pripojeni
            connection = DriverManager.getConnection("jdbc:mysql://webdev.felk.cvut.cz/koukavoj?" + "user=koukavoj&password=fd43yu6z");
            System.out.println("PRIPOJENO!");
        } catch (java.sql.SQLException ex) {
            ex.printStackTrace();            
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();            
        }



    }
}
